{% extends base %}

{% block body %}

    {% init message_tag = "" %}
    {% init default_content = "" %}
    {% init show_tab = True %}
    {% init show_input_box = True %}
    {% init show_system_tag = True %}
    {% init show_sub_link = False %}

    <script type="text/javascript" src="/static/js/message/message.js"></script>

    <input class="default-content-input" type="hidden" value="{{default_content}}"/>

    <!-- 事件转换 -->
    {% include message/component/message_event.html %}

    <!-- 菜单 -->
    {% if show_tab %}
        {% include message/component/message_header.html %}
    {% end %}

    <!-- 编辑器 -->
    {% if show_input_box %}
        {% include message/component/message_input.html %}
    {% end %}

    <!-- 系统标签 -->
    {% if show_system_tag %}
        {% include message/card/message_system_tag.html %}
    {% end %}

    <!-- 二级目录 -->
    {% if show_sub_link %}
        {% include message/component/message_sub_link.html %}
    {% end %}

    <!-- 文字区域 -->
    {% include message/component/message_list.html %}

    <script type="text/javascript">
        $(function (e) {
            function getParamTag() {
                var tag = "{{message_tag}}";
                if (tag != "") {
                    return tag;
                }
                return "{{tag}}";
            }

            function getParamPage() {
                var page = getUrlParam("page");
                if (page == undefined) {
                    return 1;
                } else {
                    return page;
                }
            }

            function getParamKey() {
                // getUrlParam 获取参数空格会被处理成`+`
                // return getUrlParam("key", "");
                return "{{key}}";
            }

            function getSearchTags() {
                return getUrlParam("searchTags", "");
            }

            function getParamDate() {
                return getUrlParam("date", "");
            }

            function getParamNoTag() {
                return getUrlParam("noTag", "");
            }

            function getParamFilterKey() {
                return getUrlParam("filterKey", "");
            }

            function getParamFilterDate() {
                return getUrlParam("filterDate", "");
            }

            function getParamOrderBy() {
                return getUrlParam("orderby", "");
            }

            function onMessageRefresh() {
                var params = {};

                params.tag  = getParamTag();
                params.page = getParamPage();
                params.key = getParamKey();
                params.searchTags = getSearchTags();
                params.date = getParamDate();
                params.noTag = getParamNoTag();
                params.filterKey = getParamFilterKey();
                params.filterDate = getParamFilterDate();
                params.orderby = getParamOrderBy();

                window.doRefreshMessageList(params);
            }

            function onMessageCreated() {
                onMessageRefresh();
            }

            xnote.on("message.updated", onMessageRefresh);
            xnote.on("message.created", onMessageCreated);

            // 定义刷新消息列表函数
            xnote.setExtFunc("message.refreshMessageList", onMessageRefresh);

            // 触发更新事件
            xnote.fire("message.updated");
        })
    </script>

{% end %}

